﻿#include "stdafx.h"
#include "AstDot.h"
#include "AstLet.h"
#include "AstCall.h"
#include "ClassInstanceType.h"
#include "ClassContext.h"
#include "CodeGenerate/CodeGen.h"

AstDot::AstDot(AstNode * o, AstNode * r)
	: object(o), right(r)
{
}

CodeGen * AstDot::makeGen(SiContext * parent)
{
	auto o = object->makeGen(parent);
	auto x = dynamic_cast<MakeContext*>(o->type);
	if (x) {	// 如果左边是对象
		auto *clsContext = x->makeContext(parent, o);
		return right->makeGen(clsContext);
	}
	else {
		throw std::runtime_error("点的左边不是对象类型");
	}
}

void AstDot::draw(std::ostream & os) {
	std::string n = nodeId;
	os << n << " -> " << object->nodeId << std::endl;
	os << n << " -> " << right << std::endl;
	os << n << "[label=\".\"]" << std::endl;
	object->draw(os);
}


